home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
414_01
/
the.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-15
|
30KB
|
824 lines
/***********************************************************************/
/* THE.C - The Hessling Editor */
/***********************************************************************/
/*
* THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
* Copyright (C) 1991-1993 Mark Hessling
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
*
* The Free Software Foundation, Inc.
* 675 Mass Ave,
* Cambridge, MA 02139 USA.
*
*
* If you make modifications to this software that you feel increases
* it usefulness for the rest of the community, please email the
* changes, enhancements, bug fixes as well as any and all ideas to me.
* This software is going to be maintained and enhanced as deemed
* necessary by the community.
*
* Mark Hessling email: M.Hessling@gu.edu.au
* 36 David Road Phone: +61 7 849 7731
* Holland Park Fax: +61 7 875 5314
* QLD 4121
* Australia
*/
/*
$Header: C:\THE\RCS\the.c 1.4 1993/09/01 16:27:17 MH Interim MH $
*/
#include <stdio.h>
#define MAIN 1
#include "the.h"
#include "proto.h"
#include <signal.h>
#if defined(DOS) || defined(OS2)
# if !defined(EMX) && !defined(GO32)
# include <direct.h>
# endif
#endif
/*--------------------------- global data -----------------------------*/
WINDOW *foot,*error_window,*divider;
VIEW_DETAILS *vd_current=(VIEW_DETAILS *)NULL;
VIEW_DETAILS *vd_first=(VIEW_DETAILS *)NULL;
VIEW_DETAILS *vd_mark=(VIEW_DETAILS *)NULL;
char number_of_views = 0; /* number of views */
char number_of_files = 0; /* number of files */
char display_screens = 1; /* number of screens */
char current_screen = 0;
SCREEN_DETAILS screen[MAX_SCREENS]; /* 2 screen structures */
bool horizontal=TRUE;
short save_coord_x[VIEW_WINDOWS];
short save_coord_y[VIEW_WINDOWS];
LINE *next_line,*curr_line;
LINE *first_file_name=NULL,*current_file_name=NULL;
bool error_on_screen=FALSE;
bool colour_support=TRUE; /* indicates if colour is supported */
char *rec;
unsigned short rec_len = 0; /* length of rec */
char *cmd_rec;
unsigned short cmd_rec_len = 0; /* length of cmd_rec */
char *pre_rec;
unsigned short pre_rec_len = 0; /* length of cmd_rec */
char focus_changed = NO; /* indicates if focus line has changed */
char current_changed = NO; /* indicates if current line has changed */
char mode_insert=NO; /* defines insert mode toggle */
char in_profile; /* indicates if processing profile */
char execute_profile; /* indicates if we are to process any profile */
char in_macro; /* indicates if processing REXX macro */
char file_read=NO; /* indicates if we have read the file */
char curses_started=NO; /* indicates if cureses has started */
#if defined(DOS) || defined(OS2)
bool extended_display_mode=TRUE; /* display all 256 characters ? */
#else
bool extended_display_mode=FALSE; /* display all 256 characters ? */
#endif
char *the_version = (char *)"1.5";
char term_name[20]; /* $TERM value */
#if defined(UNIX)
char user_home_dir[MAX_FILE_NAME+1];
# define THE_PROFILE_FILE ".therc"
#else
# define THE_PROFILE_FILE "PROFILE.THE"
#endif
char *helpfilename = (char *)"THE.HLP";
char *tempfilename = (char *)"THE.$$$";
#if !defined(NOREXX)
char *rexxoutname = (char *)"REXX.$$$";
char rexx_pathname[MAX_FILE_NAME+1];
char rexx_filename[10];
#endif
#ifdef VMS
char *dirfilename = (char *)"DIR.THE";
#else
char *dirfilename = (char *)"DIR.DIR";
#endif
char macro_suffix[12] = ".the"; /* default extension for macros */
char dir_pathname[MAX_FILE_NAME+1];
char dir_filename[10];
char curr_path[MAX_FILE_NAME+1];
char sp_path[MAX_FILE_NAME+1];
char sp_fname[MAX_FILE_NAME+1];
char dir_path[MAX_FILE_NAME+1]; /* for dir and ls commands */
char the_home_dir[MAX_FILE_NAME+1];
char the_macro_path[MAX_FILE_NAME+1]; /* for macro command */
char the_help_file[MAX_FILE_NAME+1];
char the_profile_file[MAX_FILE_NAME+1];
char *prf_arg=(char *)NULL;
bool profile_specified=FALSE;
char tabkey_insert='C';
char tabkey_overwrite='T';
unsigned short file_start = 36;
char *last_target;
#if defined(UNIX) || defined(OS2)
char *spooler_name;
#endif
char file_disposition;
struct stat stat_buf;
int reserved_top=0;
int reserved_bottom=0;
int lastrc=0;
extern DEFINE *first_define;
#if !defined(NOREXX)
extern LINE *first_prefix_synonym;
#endif
/*---------------------------------------------------------------------*/
/* Following are for getopt function(s). */
/*---------------------------------------------------------------------*/
extern char *optarg;
extern int optind;
/***********************************************************************/
#ifdef PROTO
int main(int argc, char *argv[])
#else
int main(argc,argv)
int argc;
char *argv[];
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern bool CLEARSCREENx;
/*---------------------- function definitions -------------------------*/
/*--------------------------- local data ------------------------------*/
register int i,j,k;
char *prf=(char *)NULL;
int c;
int malloc_fd;
bool trap_signals=TRUE;
bool pause_for_errors=FALSE;
int rc;
/*--------------------------- processing ------------------------------*/
#ifdef __EMX__
_wildcard(&argc,&argv);
#endif
#ifdef TRACE
trace_initialise();
trace_function("the.c: main");
#endif
/*---------------------------------------------------------------------*/
/* Set up flag to indicate that we are not interactive...yet. */
/*---------------------------------------------------------------------*/
in_profile = TRUE;
execute_profile = TRUE;
in_macro = FALSE;
/*---------------------------------------------------------------------*/
/* Initialise the printer spooler. */
/*---------------------------------------------------------------------*/
#if defined(UNIX) || defined(OS2)
if ((spooler_name = (char *)malloc(4*sizeof(char))) == NULL)
{
display_error(30,(char *)"");
exit_clean(1);
}
# ifdef UNIX
strcpy(spooler_name,(char *)"lpr");
# else
strcpy(spooler_name,(char *)"LPT1");
# endif
#endif
/*---------------------------------------------------------------------*/
/* Get all environment variables here. Some may be overridden by */
/* command-line switches. (future possibility) */
/*---------------------------------------------------------------------*/
#if defined(UNIX)
if (getenv("HOME") != NULL)
strcpy(user_home_dir,getenv("HOME"));
else
strcpy(user_home_dir,"./");
if (*(user_home_dir+strlen(user_home_dir)-1) != ISLASH)
strcat(user_home_dir,ISTR_SLASH);
if (getenv("TERM") != NULL)
strcpy(term_name,getenv("TERM"));
else
strcpy(term_name,"default");
#endif
#if defined(DOS)
strcpy(term_name,"DOS");
#endif
#if defined(OS2)
strcpy(term_name,"OS2");
#endif
/*---------------------------------------------------------------------*/
/* Get THE_HOME_DIR first (as all other paths rely on this value) */
/*---------------------------------------------------------------------*/
if (getenv("THE_HOME_DIR") != NULL)
{
strcpy(the_home_dir,getenv("THE_HOME_DIR"));
(void *)strtrans(the_home_dir,OSLASH,ISLASH);
if ((the_home_dir[strlen(the_home_dir)-1]) != ISLASH)
strcat(the_home_dir,